<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/uniform_attestation/head_beforesignon.jsp" %>               
<%@ page import="java.security.PublicKey"%>
<%@ page import="java.security.PrivateKey"%>
<%@ page import="com.icbc.ssic.base.Credentials"%>
<%@ page import="com.icbc.ssic.base.SSICUser"%>
<%@ page import="com.icbc.ssic.base.ServerSideAuthenticator"%>
<%@ page import="com.icbc.ctpdemo.uniform_attestation.*"%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="com.icbc.ctpdemo.uniform_attestation.SsicManager"%>
<%@ taglib uri="ctp-tag" prefix="ctp" %>
<%
	String SSIAuth=request.getParameter("SSIAuth");
	String SSISign=request.getParameter("SSISign");
	String siteOperationName="signIn";
	String userName="init";
	String ctpLoginUrl=request.getParameter("ctpLoginUrl");
	String ctpLoginItem=request.getParameter("ctpLoginItem");	
	if(ctpLoginItem!=null&&ctpLoginItem!=""){	
	    if(ctpLoginUrl.indexOf("?")>0){	 
	    	ctpLoginUrl=ctpLoginUrl.replaceAll("\\?","%3F");
	    }	  
	    if(ctpLoginUrl.indexOf("&")>0){	 
	    	ctpLoginUrl=ctpLoginUrl.replaceAll("&","%26");
	    }
	    if(ctpLoginUrl.indexOf("=")>0){	     
	        ctpLoginUrl=ctpLoginUrl.replaceAll("=","%3D");
	    }
	}	
%>

<jsp:useBean id="logonsign" scope="page" class="com.icbc.ssic.base.ServerSideAuthenticator">
<% 
	String serverIP = SsicManager.getInstance().getSsicIp();
	String clientIP = SsicManager.getInstance().getClientIp();	  
	String siteURL= "http://" + clientIP + path + "/index.jsp"; 
	if(ctpLoginUrl!=null&&ctpLoginItem!=null&&ctpLoginUrl!=""&&ctpLoginItem!=""){//在统一认证中增加链接参数
		siteURL=siteURL+"?ctpLoginItem="+ctpLoginItem+"&ctpLoginUrl="+ctpLoginUrl;
	}	
	String siteVersion = SsicManager.getInstance().getSsicVersion();
	String siteService = SsicManager.getInstance().getSsicClientKeyName();

	PublicKey publicKey = SsicManager.getInstance().getPublicKey();
	PrivateKey privateKey = SsicManager.getInstance().getPrivateKey();
	
	logonsign.setServerName(serverIP);
	logonsign.setVersion(siteVersion);
	logonsign.setServiceName(siteService);
	logonsign.setServiceURL(siteURL);
	logonsign.setOperation(siteOperationName);
	logonsign.setSSIPublicKey(publicKey);
	logonsign.setPrivateKey(privateKey);

	if(!logonsign.execute(request,response,SSIAuth,SSISign)){
		return;
	}
%>
</jsp:useBean>

<% 		
	Credentials cred=null;
	SSICUser user=null;
	Object obj=null;
	obj=request.getAttribute("ssiCredentials");
	if(obj!=null)
	{
		cred=(Credentials)obj;
		user=cred.getSSICUser();
		userName=user.getUserName();
		if(ctpLoginUrl==null){
			ctpLoginUrl="";
		}			
		if(ctpLoginItem==null){
			ctpLoginItem="";
		}  
        String url = "/signin.flowc?flowActionName=process0&userId=" + userName + "&ssicFlag=1&Language=zh_CN";
%>
<jsp:forward page="<%=url%>"/>
<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
12312312312
</BODY>
<%
	} else { 
%>


<HTML>
<HEAD>
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE><ctp:label key="loginmsg"/></TITLE>

</HEAD>
<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<ctp:label key="logonermsg"/><br>
<br>
<center><a href="javascript:window.history.go(-1)"><ctp:label key="returnbutton"/></a></center>
<br>
</BODY>
</HTML>

<%	  }
%>
